package yk.bwie.liu_news;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import fragment.MainFragment1;
import view.ViewPagerIndicator;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewpager;
    private ViewPagerIndicator viewpagerindicator;
    private String[] title_array = {"AAAAAA","BBBBBB","CCCCCC","DDDDDD","EEEEEE","FFFFFF","GGGGGG","HHHHHH"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /*Base base=new Base(){

            @Override
            public void setResultData(String data) {
                Toast.makeText(MainActivity.this, data+"---", Toast.LENGTH_SHORT).show();
            }

            @Override
            protected void setFailResult(int code) {
                Toast.makeText(MainActivity.this, "fail"+code, Toast.LENGTH_SHORT).show();
            }
        };
        base.getData("http://www.baidu.com",1000*60);*/
        viewpagerindicator = (ViewPagerIndicator) findViewById(R.id.viewpagerindicator);
        viewpager = (ViewPager) findViewById(R.id.viewpager);
        viewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {

                return MainFragment1.getInstance(title_array[position]);
            }

            @Override
            public int getCount() {
                return title_array.length;
            }
            //获取当前页面展示的标题
            @Override
            public CharSequence getPageTitle(int position) {
                return title_array[position];
            }
        });
        //设置相关联
        viewpagerindicator.setViewPager(viewpager);
    }
}
